#include <GameEngine/Gameplay/Statistics/statistics.h>


#ifdef GAMEENGINE_NAMESPACES
namespace GameEngine {
#endif

//=================================================================================


GAMEENGINE_IMPLEMENT_RTTI(Statistics)

//! Default constructor
/*!
 @note The current and maximum values of the statistics are defaulted to 0
 */
Statistics::Statistics() : maximum_stat_(0.0f), current_stat_(0.0f), locked_(false) {}

//! Constructor
/*!
 @param maximum_stat The maximum value of the statistics
 @param current_stat The current value of the statistics
 */
Statistics::Statistics(float maximum_stat, float current_stat) :
	maximum_stat_(maximum_stat), current_stat_(current_stat), locked_(false) {}

//! Copy constructor
/*!
 @param rhs The object to copy
 */
Statistics::Statistics(const Statistics& rhs) :
	maximum_stat_(rhs.maximum_stat_), current_stat_(rhs.current_stat_), locked_(rhs.locked_) {}

//! Assignment operator
/*!
 @param rhs The object to copy
 */
Statistics& Statistics::operator=(const Statistics& rhs) {
	if ( &rhs != this ) {
		maximum_stat_ = rhs.maximum_stat_;
		current_stat_ = rhs.current_stat_;
		locked_ = rhs.locked_;
	}
	return *this;
}

//! Destructor
Statistics::~Statistics() {}

//! Accessor to the maximum value of the statistics (read only)
/*!
 @return The maximum value of the statistics
 */
float Statistics::maximum_stat() const {
	return maximum_stat_;
}

//! Change the maximum value of the statistics
/*!
 @param value The new maximum value of the statistics
 @return True if value was modified, false otherwise
 */
bool Statistics::set_maximum_stat(float value) {
	if ( locked_ ) return false;
	maximum_stat_ = value;
	return true;
}

//! Accessor to the current value of the statistics (read only)
/*!
 @return The current value of the statistics
 */
float Statistics::current_stat() const {
	return current_stat_;
}

//! Change the current value of the statistics
/*!
 @param value The new current value of the statistics
 @return True if value was modified, false otherwise
 */
bool Statistics::set_current_stat(float value) {
	if ( locked_ ) return false;
	current_stat_ = value;
	return true;
}

//! Add given value to the statistics
/*!
 @param value The value to add to the statistics
 @param type Indicate which elements of the statistics should be modified
 @return True if value was (were) modified, false otherwise
 */
bool Statistics::offset_stat(float value, StatElement type) {
	if ( locked_ ) return false;
	if ( type == MaximumOnly ) maximum_stat_ += value;
	else if ( type == CurrentOnly ) current_stat_ += value;
	else {
		maximum_stat_ += value;
		current_stat_ += value;
	}
	return true;
}

//! Accessor to the lock state of the statistics (read only)
/*!
 @return The lock state of the statistics
 */
bool Statistics::locked() const {
	return locked_;
}

//! Accessor to the lock state of the statistics (read-write)
/*!
 @return A reference to the lock state of the statistics
 */
bool& Statistics::locked() {
	return locked_;
}

#ifdef GAMEENGINE_NAMESPACES
} // namespace GameEngine
#endif
